<div ng-controller="invoiceListCtrl">
    <div class="table-header table-header-border clearfix ng-scope">
        <span class="fl lh30 f14">发票管理</span>
    </div>
    <div>
        <my-nav data-nav-items="filterDataType" onchanged="changeQuery" data-title="发票类型:"></my-nav>
        <my-nav data-nav-items="filterDataStatus" onchanged="changeQuery" data-title="发票状态:"></my-nav>
        <my-nav data-nav-items="invoiceMixReceipt" onchanged="changeQuery" data-title="只显示发票收据并存的合同:"></my-nav>
    </div>
    <div class="section-table mt20">
        <div class="table-header lh30 pb5 clearfix">
            <span class="fl f14">发票列表</span>

            <div class="fr btn-group">
                <div class="fl" ng-show="userAuthList.indexOf('0200') !== -1">
                    <span class="fl">开票时间：</span>
                    <input type="text" class="fl input-text w120 ml3 input-date"
                           ng-model="query.invoice_begin_date"
                           ng-enter="query.execute()" ui-date format="yyyy-MM-dd">
                    <span class="fl ml3">-</span>
                    <input type="text" class="fl input-text w120 ml3 input-date" ng-model="query.invoice_end_date"
                           ng-enter="query.execute()" ui-date format="yyyy-MM-dd">
                </div>
                <input type="text" class="fl input-text w200 ml3" placeholder="发票台头/发票号码/合同编号"
                       ng-if="userAuthList.indexOf('0200') !== -1"
                       ng-model="query.searchKey"
                       ng-enter="query.execute()">
                <button class="btn"
                        ng-if="userAuthList.indexOf('0200') !== -1"
                        ng-click="query.execute()">查询</button>
                <!--<button class="btn btn-yellow" ng-click="editInvoice(0)">新建发票</button>-->
                <!--<button class="btn btn-yellow" ng-click="editInvoice(1)">新建主发票</button>-->
                <div class="download-dropdown" ng-show="userAuthList.indexOf('0201') !== -1">
                    <button class="btn" type="button" ng-click="dropdownShow2 = dropdownShow2 ? false : true">新增发票</button>
                    <ul class="dropdown-menu" aria-labelledby="dropdownMenu2" ng-show="dropdownShow2">
                            <li ui-dialog="新增发票"
                            ui-dialog-data="{}"
                            ui-dialog-show="invoiceService.onInvoiceShow($dialog,$dialogScope, 1)"
                            ui-dialog-ok="invoiceService.editInvoiceSave($data,$dialog,$dialogScope,query.execute,page_index)"
                            ui-dialog-on-close="invoiceService.onCloseInvoice($dialogScope,1)"
                            ui-dialog-cache="false"
                            ui-dialog-url="${require('./dialog/invoice_add.html?url')}">
                            <a href="javascript:;" id="addVoiceButton">新增发票</a>
                        </li>
                        <li id="importInvoice" class="fileinput-button">
                            <a href="javascript:;">批量导入</a>
                            <input type="file" name="file" accept=".xls,.xlsx" queueLimit="1">
                        </li>
                        <li>
                            <a href="{{invoiceImportTpl}}"  >下载导入模板</a>
                        </li>
                    </ul>
                </div>
                <button class="btn btn-yellow" id="addMainVoiceButton"
                        ng-show="userAuthList.indexOf('0201') !== -1"
                        ui-dialog="新增主发票"
                        ui-dialog-data="{}"
                        ui-dialog-show="invoiceService.onInvoiceShow($dialog,$dialogScope, 2)"
                        ui-dialog-ok="invoiceService.editInvoiceSave($data,$dialog,$dialogScope,query.execute,page_index)"
                        ui-dialog-on-close="invoiceService.onCloseInvoice($dialogScope,2)"
                        ui-dialog-cache="false"
                        ui-dialog-url="${require('./dialog/invoice_add.html?url')}"
                        >新增主发票
                </button>
                <div class="download-dropdown" ng-show="userAuthList.indexOf('0202') !== -1">
                    <button class="btn" type="button" ng-click="dropdownShow = dropdownShow ? false : true">导出</button>
                    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1" ng-show="dropdownShow">
                        <li><a href="javascript:;" ng-click="downloadInvoices()">导出发票</a></li>
                        <li><a href="javascript:;" ng-click="downloadOtherDetails()">导出未关联发票的回款明细</a></li>
                        <li><a href="javascript:;" ng-click="downloadReceipt()">导出收据</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="table-responsive mt10">
            <table class="table table-hover">
                <!-- 表头-->
                <thead>
                <tr>
                    <th width="40" class="text-center">序号</th>
                    <th width="180">开票单位</th>
                    <th width="150">合同信息</th>
                    <th width="180">发票信息</th>
                    <th width="120">发票状态</th>
                    <th width="160">金额信息</th>
                    <th width="100">附加信息</th>
                    <th>操作</th>
                </tr>
                </thead>
                <!-- 表格内容-->
                <tbody>
                <tr ng-repeat="record in invoices" class="table-tr" >
                    <td class="text-center"><p ng-bind="$index + 1 + startPageIndex"></p></td>
                    <td>
                        <p ng-bind="record.invoiceCompanyName"></p>
                    </td>
                    <td>
                        <a ng-href="/contract/edit.shtml#/base?id={{record.contract_id}}"
                           ng-style="{color: '#333'}"
                           target="_blank">
                            <p class="get-contract-detail" ng-bind="record.contractCode"></p>
                            <p ng-if="record.contractCompanyName" class="tab-text-gray">
                                合同所属公司：
                                <span ng-bind="record.contractCompanyName"></span>
                            </p>
                        </a>
                    </td>
                    <td>
                        <p>发票台头：<span ng-bind="record.customer_name"></span></p>

                        <p>发票号码：<span class="get-contract-detail" ng-bind="record.invoice_no" ng-click="rowDbClick($index)"></span></p>

                        <p class="tab-text-gray">开票日期：<span ng-bind="record.invoice_date | strdate:'yyyy-MM-dd'"></span></p>
                    </td>
                    <td>
                        <p ng-if="record.is_main_invoice==0">普通发票</p>

                        <p ng-if="record.is_main_invoice==1">主发票</p>

                        <p ng-if="record.invoice_status!=1">未/部分关联</p>

                        <p ng-if="record.invoice_status==1">已全部关联</p>
                    </td>
                    <td>
                        <p>发票金额：<span ng-bind="record.invoice_amount | number:2"></span></p>

                        <div ng-if="record.is_main_invoice==0">
                            <p class="tab-text-gray">已开票未回款：{{record.invoice_amount - record.payment_amount | number:2}}</p>

                            <p class="tab-text-gray">关联应收款：{{record.receivables_amount | number:2}}</p>
                        </div>
                        <div ng-if="record.is_main_invoice==1">
                            <p>子发票金额：{{record.totalChildInvoiceAmount | number:2}}</p>
                        </div>
                    </td>
                    <td>
                        <p>
                            {{ record.is_red_invoice == 1 ? '红冲发票' : record.is_reded_invoice == 1 ? '被红冲发票' : '正常发票'}}
                        </p>
                        <p>是否遗失：
                            <span ng-if="record.is_lose==1">是</span>

                            <span ng-if="record.is_lose!=1">否</span>
                        </p>
                    </td>
                    <td>
                        <div>
                            <p ng-if="record.is_red_invoice!=1 && !record.red_by_invoice_id">
                                <!--<a href="javascript:;" ng-click="editInvoice(2,record.invoice_id)">复制</a>-->
                                <a href="javascript:;"
                                   class="tab-text"
                                   ng-show="userAuthList.indexOf('0201') !== -1"
                                   ui-dialog="复制发票"
                                   ui-dialog-data="{}"
                                   ui-dialog-show="invoiceService.onInvoiceShow($dialog,$dialogScope, 3,record.invoice_id)"
                                   ui-dialog-ok="invoiceService.editInvoiceSave($data,$dialog,$dialogScope,query.execute,page_index)"
                                   ui-dialog-cache="false"
                                   ui-dialog-url="${require('./dialog/invoice_add.html?url')}"
                                >复制
                                </a>
                            </p>
                            <p ng-if="record.is_reded_invoice == 0 && record.is_red_invoice == 0">
                                <a href="javascript:void(0)"
                                   class="tab-text"
                                   ng-show="userAuthList.indexOf('0201') !== -1"
                                   title="红冲发票"
                                   ui-dialog="新增红冲发票"
                                   ui-dialog-data="{}"
                                   ui-dialog-show="invoiceService.onInvoiceShow($dialog,$dialogScope, 6,record.invoice_id)"
                                   ui-dialog-ok="invoiceService.editInvoiceSave($data,$dialog,$dialogScope,query.execute,page_index,6)"
                                   ui-dialog-cache="false"
                                   ui-dialog-url="${require('./dialog/invoice_add.html?url')}"
                                >红冲此发票</a>
                            </p>
                            <p ng-if="!(record.receivables_amount>0) && record.is_red_invoice!=1 && !record.red_by_invoice_id">
                                <!--<a href="javascript:;" ng-click="editInvoice(3,record.invoice_id)">编辑</a>-->
                                <a id='editInvoiceButton{{$index}}'
                                   href="javascript:;"
                                   class="tab-text"
                                   ng-show="userAuthList.indexOf('0201') !== -1"
                                   ui-dialog="编辑发票"
                                   ui-dialog-data="{}"
                                   ui-dialog-show="invoiceService.onInvoiceShow($dialog,$dialogScope, 4,record.invoice_id)"
                                   ui-dialog-ok="invoiceService.editInvoiceSave($data,$dialog,$dialogScope,query.execute,page_index)"
                                   ui-dialog-cache="false"
                                   ui-dialog-url="${require('./dialog/invoice_add.html?url')}"
                                >编辑
                                </a>
                            </p>
                            <p ng-if="record.receivables_amount>0 || record.is_red_invoice==1 || record.red_by_invoice_id">
                                <!--<a href="javascript:;" ng-click="editInvoice(4,record.invoice_id)">查看</a>-->
                                <a id='readInvoiceButton{{$index}}'
                                   href="javascript:;"
                                   class="tab-text"
                                   ui-dialog="查看发票"
                                   ui-dialog-data="{}"
                                   ui-dialog-show="invoiceService.onInvoiceShow($dialog,$dialogScope, 5,record.invoice_id)"
                                   ui-dialog-ok="query.execute(page_index)"
                                   ui-dialog-cache="false"
                                   ui-dialog-url="${require('./dialog/invoice_add.html?url')}"
                                >查看
                                </a>
                            </p>
                            <p ng-if="!(record.receivables_amount>0)">
                                <a href="javascript:;"
                                   class="tab-text"
                                   ng-click="removeInvoice(record.invoice_id)"
                                   ng-show="userAuthList.indexOf('0201') !== -1">删除</a>
                            </p>
                            <p ng-if="record.is_lose!=1">
                                <a href="javascript:;"
                                   class="tab-text"
                                   ng-click="markLoss(record.invoice_id)"
                                   ng-show="userAuthList.indexOf('0201') !== -1">标记遗失</a>
                            </p>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="no-data" ng-if="invoices.length == 0"><span>暂无数据</span></div>
        </div>
        <div id="pagination" class="pagination"></div>
    </div>

</div>